#!/usr/bin/python
import web
from lib import chkuser,render,MC,loadHtmlFile,chklogin
from config import *
mc = MC(userDB)
class login:
    def POST(self):
        i = web.input()
        user = i.user.encode('UTF-8')
        passwd = i.passwd.encode('UTF-8')
#        print mc.get(user)
        if(chkuser(user,mc) or mc.get(user) != passwd):
            return "username not exists or password error"
        web.setcookie('user',user)
        web.setcookie('passwd',passwd)
        html = loadHtmlFile('%slogin_res.html' % (htmlPath)) 
        return html
    def GET(self):
        if(chklogin(web,mc)):
            return loadHtmlFile('%slogin_res.html' % (htmlPath)) 
        else:
            return render()

